<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width,height=device-height,initial-scale=1.0,user-scalable=0">
<title>APICloud</title>
<link rel="stylesheet" type="text/css" href="../css/base.css" />
<link rel="stylesheet" type="text/css" href="../css/common.css" />

</head>
<body>
	<div id="wrap">
		<div id="main">
			<div>
				<input style="height: 35px" type="button" onclick="listAppInfo()" value="获取app列表" /> 
				<input style="height: 35px" type="button" onclick="listWifiInfo()" value="获取wifi列表" /><br> <br> 
				<input style="height: 35px" type="button" onclick="add()" value="增加数据到共享内存" /> 
				<input style="height: 35px" type="button" onclick="get()" value="获取共享内存数据" />	<br> 
				<input style="height: 35px" type="button" onclick="del()" value="删除共享内存数据" />
				<input style="height: 35px" type="button" onclick="edit()" value="更新共享内存数据" /><br> <br> 
				<input style="height: 35px" type="button" onclick="onWake()" value="定时唤醒" />
				<div style="font-size: 0.8em;">ap</div>
				<input type="text" id="ap" value="zw" /><br>
				<div style="font-size: 0.8em;">pwd</div>
				<input type="text" id="pwd" value="zw1234567890" /><br> 
				<input style="height: 35px" type="button" onclick="onWifi()" value="连接wifi" />
			</div>
		</div>
	</div>

	<script type="text/javascript">
		apiready = function() {
			app = api.require('moduleApp');
			wifi = api.require('moduleWifi');
			dd = api.require('moduleDataDocker');
			wake = api.require('moduleAlarmTimer');
		}
		
		var times = 0;
		function notes(ret, error) {
			api.toast({
				msg : ret + "; js run times:" + (times++),
				duration : 4000,
				location : "top"
			});
		}
		var cnt = 0;
		function onWake() {
			if (cnt++ % 2 == 0) {
				wake.wakeSleep({
					cmd : "stop",
					time : 20
				}, function(ret, error) {
				});
			} else {
				wake.wakeSleep({
					cmd : "start",
					time : 5
				}, notes);
			}
		}

		function onWifi() {
			var ap = document.getElementById("ap").value;
			var pwd = document.getElementById("pwd").value;

			var wifiCfg = {};
			wifiCfg.ap = ap;
			wifiCfg.pwd = pwd;
			wifiCfg.cipher = 1;

			wifi.addNetWork(wifiCfg, function(ret, error) {
				alert(ret);
			});
		}

		function listAppInfo() {
			alert(app.listAppInfo);
		}

		function listWifiInfo() {
			alert(wifi.listWifiInfo);
		}
		function add() {
			var sd = {};
			sd.name = "sd";
			sd.data = "123456"
			dd.add(sd, function(ret, error) {
				alert(ret + error);
			});
		}
		function get() {
			var sd = {};
			sd.name = "wifi";
			dd.get(sd, function(ret, error) {
				alert(ret.name + ret.data + error);
			});
		}
		function del() {
			var sd = {};
			sd.name = "sd";
			dd.del(sd, function(ret, error) {
				alert(ret + error);
			});
		}
		function edit() {
			var sd = {};
			sd.name = "sd";
			sd.data = "ABCDEFG"
			dd.add(sd, function(ret, error) {
				alert(ret + error);
			});
		}
	</script>
</body>
</html>